<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.10.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>common_util: src/common_util/singleton.h File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="clipboard.js"></script>
<script type="text/javascript" src="cookie.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">common_util
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.10.0 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="dir_2961cad218251a7c35c6867350b80887.html">common_util</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#define-members">Macros</a>  </div>
  <div class="headertitle"><div class="title">singleton.h File Reference</div></div>
</div><!--header-->
<div class="contents">

<p>Define some macro definitions for singleton pattern implementations. For convenience to use, this file defined some macro definitions about singleton pattern implementations.  
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &lt;mutex&gt;</code><br />
</div>
<p><a href="singleton_8h_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="define-members" name="define-members"></a>
Macros</h2></td></tr>
<tr class="memitem:a8f0365b2a51b6cd09037b83c5df250d7" id="r_a8f0365b2a51b6cd09037b83c5df250d7"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a8f0365b2a51b6cd09037b83c5df250d7">CUTL_COPY_AND_ASSIGN</a>(classname)</td></tr>
<tr class="memdesc:a8f0365b2a51b6cd09037b83c5df250d7"><td class="mdescLeft">&#160;</td><td class="mdescRight">Macro definition for constructor and copy-assignment operator.  <br /></td></tr>
<tr class="separator:a8f0365b2a51b6cd09037b83c5df250d7"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a955faef8343c1603d8acb2b46572e7c9" id="r_a955faef8343c1603d8acb2b46572e7c9"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a955faef8343c1603d8acb2b46572e7c9">CUTL_SINGLETON_PTR</a>(classname)</td></tr>
<tr class="memdesc:a955faef8343c1603d8acb2b46572e7c9"><td class="mdescLeft">&#160;</td><td class="mdescRight">Macro definition for get singleton instance pointer implaementation.  <br /></td></tr>
<tr class="separator:a955faef8343c1603d8acb2b46572e7c9"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a18256d54de956ff9be4d6887354737d5" id="r_a18256d54de956ff9be4d6887354737d5"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a18256d54de956ff9be4d6887354737d5">CUTL_SINGLETON_PTR_DEFAULT_CTOR</a>(classname)</td></tr>
<tr class="memdesc:a18256d54de956ff9be4d6887354737d5"><td class="mdescLeft">&#160;</td><td class="mdescRight">Macro definition for get singleton instance pointer implementation with default constructor.  <br /></td></tr>
<tr class="separator:a18256d54de956ff9be4d6887354737d5"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ae6202f16d5076942a5a57bd3feea2d1e" id="r_ae6202f16d5076942a5a57bd3feea2d1e"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#ae6202f16d5076942a5a57bd3feea2d1e">CUTL_SINGLETON_REF</a>(classname)</td></tr>
<tr class="memdesc:ae6202f16d5076942a5a57bd3feea2d1e"><td class="mdescLeft">&#160;</td><td class="mdescRight">Macro definition for get singleton instance reference implaementation.  <br /></td></tr>
<tr class="separator:ae6202f16d5076942a5a57bd3feea2d1e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a4b31c1f99744b5d01441b61e30f4903c" id="r_a4b31c1f99744b5d01441b61e30f4903c"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a4b31c1f99744b5d01441b61e30f4903c">CUTL_SINGLETON_REF_DEFAULT_CTOR</a>(classname)</td></tr>
<tr class="memdesc:a4b31c1f99744b5d01441b61e30f4903c"><td class="mdescLeft">&#160;</td><td class="mdescRight">Macro definition for get singleton instance reference implementation with default constructor.  <br /></td></tr>
<tr class="separator:a4b31c1f99744b5d01441b61e30f4903c"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Define some macro definitions for singleton pattern implementations. For convenience to use, this file defined some macro definitions about singleton pattern implementations. </p>
<dl class="section copyright"><dt>Copyright</dt><dd>Copyright (c) 2024, Spencer.Luo. All Rights Reserved.</dd></dl>
<p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at </p><pre class="fragment">  http://www.apache.org/licenses/LICENSE-2.0
</pre><p> Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations.</p>
<dl class="section author"><dt>Author</dt><dd>spencer.luo </dd></dl>
<dl class="section date"><dt>Date</dt><dd>2024-05-13 </dd></dl>
</div><h2 class="groupheader">Macro Definition Documentation</h2>
<a id="a8f0365b2a51b6cd09037b83c5df250d7" name="a8f0365b2a51b6cd09037b83c5df250d7"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a8f0365b2a51b6cd09037b83c5df250d7">&#9670;&#160;</a></span>CUTL_COPY_AND_ASSIGN</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define CUTL_COPY_AND_ASSIGN</td>
          <td>(</td>
          <td class="paramtype"></td>          <td class="paramname"><span class="paramname">classname</span></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<b>Value:</b><div class="fragment"><div class="line">    classname(<span class="keyword">const</span> classname &amp;) = <span class="keyword">delete</span>; \</div>
<div class="line">    classname &amp;operator=(<span class="keyword">const</span> classname &amp;) = <span class="keyword">delete</span>;</div>
</div><!-- fragment -->
<p>Macro definition for constructor and copy-assignment operator. </p>

</div>
</div>
<a id="a955faef8343c1603d8acb2b46572e7c9" name="a955faef8343c1603d8acb2b46572e7c9"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a955faef8343c1603d8acb2b46572e7c9">&#9670;&#160;</a></span>CUTL_SINGLETON_PTR</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define CUTL_SINGLETON_PTR</td>
          <td>(</td>
          <td class="paramtype"></td>          <td class="paramname"><span class="paramname">classname</span></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<b>Value:</b><div class="fragment"><div class="line"><span class="keyword">public</span>:                                                                          \</div>
<div class="line">    <span class="keyword">static</span> classname *get_instance(<span class="keywordtype">bool</span> create_if_needed = <span class="keyword">true</span>)                 \</div>
<div class="line">    {                                                                            \</div>
<div class="line">        <span class="keyword">static</span> classname *obj = <span class="keyword">nullptr</span>;                                         \</div>
<div class="line">        if (!obj &amp;&amp; create_if_needed)                                            \</div>
<div class="line">        {                                                                        \</div>
<div class="line">            <span class="keyword">static</span> std::once_flag flag;                                          \</div>
<div class="line">            std::call_once(flag, [&amp;] { obj = <span class="keyword">new</span> (std::nothrow) classname(); }); \</div>
<div class="line">        }                                                                        \</div>
<div class="line">        <span class="keywordflow">return</span> obj;                                                              \</div>
<div class="line">    }                                                                            \</div>
<div class="line">    ~classname();                                                                \</div>
<div class="line">                                                                                 \</div>
<div class="line"><span class="keyword">private</span>:                                                                         \</div>
<div class="line">    classname();                                                                 \</div>
<div class="line">    CUTL_COPY_AND_ASSIGN(classname)</div>
</div><!-- fragment -->
<p>Macro definition for get singleton instance pointer implaementation. </p>

</div>
</div>
<a id="a18256d54de956ff9be4d6887354737d5" name="a18256d54de956ff9be4d6887354737d5"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a18256d54de956ff9be4d6887354737d5">&#9670;&#160;</a></span>CUTL_SINGLETON_PTR_DEFAULT_CTOR</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define CUTL_SINGLETON_PTR_DEFAULT_CTOR</td>
          <td>(</td>
          <td class="paramtype"></td>          <td class="paramname"><span class="paramname">classname</span></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<b>Value:</b><div class="fragment"><div class="line"><span class="keyword">public</span>:                                                                          \</div>
<div class="line">    <span class="keyword">static</span> classname *get_instance(<span class="keywordtype">bool</span> create_if_needed = <span class="keyword">true</span>)                 \</div>
<div class="line">    {                                                                            \</div>
<div class="line">        <span class="keyword">static</span> classname *obj = <span class="keyword">nullptr</span>;                                         \</div>
<div class="line">        if (!obj &amp;&amp; create_if_needed)                                            \</div>
<div class="line">        {                                                                        \</div>
<div class="line">            <span class="keyword">static</span> std::once_flag flag;                                          \</div>
<div class="line">            std::call_once(flag, [&amp;] { obj = <span class="keyword">new</span> (std::nothrow) classname(); }); \</div>
<div class="line">        }                                                                        \</div>
<div class="line">        <span class="keywordflow">return</span> obj;                                                              \</div>
<div class="line">    }                                                                            \</div>
<div class="line">    ~classname();                                                                \</div>
<div class="line">                                                                                 \</div>
<div class="line"><span class="keyword">private</span>:                                                                         \</div>
<div class="line">    classname() = <span class="keywordflow">default</span>;                                                       \</div>
<div class="line">    CUTL_COPY_AND_ASSIGN(classname)</div>
</div><!-- fragment -->
<p>Macro definition for get singleton instance pointer implementation with default constructor. </p>

</div>
</div>
<a id="ae6202f16d5076942a5a57bd3feea2d1e" name="ae6202f16d5076942a5a57bd3feea2d1e"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ae6202f16d5076942a5a57bd3feea2d1e">&#9670;&#160;</a></span>CUTL_SINGLETON_REF</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define CUTL_SINGLETON_REF</td>
          <td>(</td>
          <td class="paramtype"></td>          <td class="paramname"><span class="paramname">classname</span></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<b>Value:</b><div class="fragment"><div class="line"><span class="keyword">public</span>:                                                          \</div>
<div class="line">    <span class="keyword">static</span> classname &amp;get_instance(<span class="keywordtype">bool</span> create_if_needed = <span class="keyword">true</span>) \</div>
<div class="line">    {                                                            \</div>
<div class="line">        <span class="keyword">static</span> classname obj;                                    \</div>
<div class="line">        <span class="keywordflow">return</span> obj;                                              \</div>
<div class="line">    }                                                            \</div>
<div class="line">    ~classname();                                                \</div>
<div class="line">                                                                 \</div>
<div class="line"><span class="keyword">private</span>:                                                         \</div>
<div class="line">    classname();                                                 \</div>
<div class="line">    CUTL_COPY_AND_ASSIGN(classname)</div>
</div><!-- fragment -->
<p>Macro definition for get singleton instance reference implaementation. </p>

</div>
</div>
<a id="a4b31c1f99744b5d01441b61e30f4903c" name="a4b31c1f99744b5d01441b61e30f4903c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a4b31c1f99744b5d01441b61e30f4903c">&#9670;&#160;</a></span>CUTL_SINGLETON_REF_DEFAULT_CTOR</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define CUTL_SINGLETON_REF_DEFAULT_CTOR</td>
          <td>(</td>
          <td class="paramtype"></td>          <td class="paramname"><span class="paramname">classname</span></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<b>Value:</b><div class="fragment"><div class="line"><span class="keyword">public</span>:                                                          \</div>
<div class="line">    <span class="keyword">static</span> classname &amp;get_instance(<span class="keywordtype">bool</span> create_if_needed = <span class="keyword">true</span>) \</div>
<div class="line">    {                                                            \</div>
<div class="line">        <span class="keyword">static</span> classname obj;                                    \</div>
<div class="line">        <span class="keywordflow">return</span> obj;                                              \</div>
<div class="line">    }                                                            \</div>
<div class="line">    ~classname();                                                \</div>
<div class="line">                                                                 \</div>
<div class="line"><span class="keyword">private</span>:                                                         \</div>
<div class="line">    classname() = <span class="keywordflow">default</span>;                                       \</div>
<div class="line">    CUTL_COPY_AND_ASSIGN(classname)</div>
</div><!-- fragment -->
<p>Macro definition for get singleton instance reference implementation with default constructor. </p>

</div>
</div>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.10.0
</small></address>
</body>
</html>
